#include "scalar.h"
#include <sstream>

Scalar::Scalar(double s_mass_, double offset_, int n_):
s_mass(s_mass_), offset(offset_), n(n_),
  s_couple( sqrt(s_mass_*s_mass_ - offset_*offset_)*sqrt(2)/v )
{
  double v_phi=v/sqrt(2.);
  double v_phi2=v*v/2;

  //string for mass factors
  //g*v^2
  string mass_v="([2]*[1])";
  string mass_h="([2]*x^2)";

  //coleman weinberg
  double factor=1/(64*PI*PI);

  stringstream formula;
  formula << "[0]*("
    
    //log term 2*mh^4*log(mh/mv)
	  << "2*"<<mass_h<<"^2*log("
	  <<mass_h<<"/"<<mass_v<<")"

    //-3/2 mh^4
	  << "-3*"<<mass_h<<"^2/2"

    //+2 mh^2 mv^2
	  << "+2*"<<mass_h<<"*"<<mass_v<<")";
    
  V_loop_S=new TF1("V_loop_S", 
		     formula.str().c_str(),
		     -5000, 5000);

  //1 real scalar = 1
  V_loop_S->SetParameter(0, factor);
  V_loop_S->SetParameter(1, v_phi2);

  //top yukawa coupling
  V_loop_S->SetParameter(2, s_couple);

}

double Scalar::operator()(double x, double T) const
{
  double V0= SM(x, T);

  if(x*x < 1e-20)
    x=1e-10;

  V0 += n*V_loop_S->Eval(x);

  //now add scalar contributions temperature dependent terms
  if(T>0)
    {
      double T4=T*T*T*T;
      
      //m over T neglecting coupling
      double mT=x/T;

      //multiplicity factors:
      //top = 4, W=6, Z=3, h=1
      V0+=T4*(
	      n*tint_boson(s_couple*mT)
	      );
    }

  return V0;
}

/*
TGraph* Scalar::GetGraph(double T) const
{
  vector<double> x;
  vector<double> y;
  for(int i=-300; i<=300; i+=2)
    {
      x.push_back(i);
      y.push_back((*this)(i,T));
    }

  TGraph* g=new TGraph(x.size(), &x[0], &y[0]);

  stringstream sout;
  sout<<"T_"<<T;
  g->SetName(sout.str().c_str());
  return g;
}
*/
